package com.hbnu.controller;

import com.hbnu.pojo.Request;
import com.hbnu.pojo.Result;
import com.hbnu.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@CrossOrigin(origins = "*")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/getTolPrice")
    public Result getTolPrice(@RequestBody Request rq){
        return Result.success(orderService.getTolPrice(rq));
    }

    @PostMapping("/previewOrder")
    public Result previewOrder(@RequestBody Request rq){
        return Result.success(orderService.previewOrder(rq));
    }

    @PostMapping("/createOrder")
    public Result createOrder(@RequestBody Request rq){
        try{
            String oid=orderService.createOrder(rq);
            return Result.success(oid);
        }catch (Exception e){
            return Result.error("存货不足");
        }
    }

    @PostMapping("/getOrderDetail")
    public Result getOrderDetail(@RequestBody Request rq){
        return Result.success(orderService.getOrderDetail(rq));
    }

    @PostMapping("/getOrderList")
    public Result getOrderList(){
        return Result.success(orderService.getOrderList());
    }
    @PostMapping("/getOrderListByUid")
    public Result getOrderListByUid(@RequestBody Request rq){
        return Result.success(orderService.getOrderListByUid(rq));
    }

    @PostMapping("/getOrderListByContent")
    public Result getOrderListByContent(@RequestBody Request rq){
        return Result.success(orderService.getOrderListByContent(rq));
    }
    @PostMapping("/getOrderListByUidAndState")
    public Result getOrderListByUidAndState(@RequestBody Request rq){
        return Result.success(orderService.getOrderListByUidAndState(rq));
    }

    @PostMapping("/getOrderListByStateAndContent")
    public Result getOrderListByStateAndContent(@RequestBody Request rq){
        return Result.success(orderService.getOrderListByStateAndContent(rq));
    }

    @PostMapping("/getRefundListByContent")
    public Result getRefundListByContent(@RequestBody Request rq){
        return Result.success(orderService.getRefundListByContent(rq));
    }

    @PostMapping("/getRefundListByStateAndContent")
    public Result getRefundListByStateAndContent(@RequestBody Request rq){
        return Result.success(orderService.getRefundListByStateAndContent(rq));
    }
    @PostMapping("/updateOrderAddress")
    public Result updateOrderAddress(@RequestBody Request rq){
        orderService.updateOrderAddress(rq);
        return Result.success();
    }

    @PostMapping("/paySuccessful")
    public Result paySuccessful(@RequestBody Request rq){
        orderService.paySuccessful(rq);
        return Result.success();
    }

    @PostMapping("/reOrder")
    public Result reOrder(@RequestBody Request rq){
        orderService.reOrder(rq);
        return Result.success();
    }

    @PostMapping("/refund")
    public Result refund(@RequestBody Request rq){
        try{
            orderService.refund(rq);
            return Result.success();
        }catch (Exception e){
            return Result.error("重复申请");
        }
    }

    @PostMapping("/deliverGood")
    public Result deliverGood(@RequestBody Request rq){
        return Result.success(orderService.deliverGood(rq));
    }

    @PostMapping("/refuteRefund")
    public Result refuteRefund(@RequestBody Request rq){
        orderService.refuteRefund(rq);
        return Result.success();
    }

    @PostMapping("/agreeRefund")
    public Result agreeRefund(@RequestBody Request rq){
        orderService.agreeRefund(rq);
        return  Result.success();
    }
}
